package edu.sctu.zcy.month201505.subwaysystem.V3;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created by user24 on 2015/6/4.
 */
public class MetroStation {

    public MonitorMachine monitorMachine;
    public MonitorPerson monitorPerson;
    public MonitorSystem monitorSystem;
    public Salesman salesman = new Salesman();
    public List<Passenger> passengerList;
    public DeductionsRules deductionsRules;
    HashMap<String, Integer> stations =  new HashMap<>();


    public MetroStation() {

        salesman = new Salesman();
        monitorPerson = new MonitorPerson();
        monitorSystem = new MonitorSystem();


        deductionsRules = new DeductionsRules();

        monitorMachine = new MonitorMachine();
        initPassengers();
        initStations();

    }
    private void initPassengers() {
        passengerList = new ArrayList<>();

        Passenger passenger1 = new Passenger();
        passenger1.name = "张三";
        passenger1.setCard(true);
        passenger1.card.setBalance(10);
        passenger1.setPackage(true);
        passenger1.package1.name = "易燃";
        passenger1.setWater(true);
        passenger1.water.name = "矿泉水";
        passenger1.route.startStation = "龙泉";
        passenger1.route.endStation = "犀浦";
        passenger1.setAction("偷摸别人钱包");
        passengerList.add(passenger1);

        Passenger passenger2 = new Passenger();
        passenger2.name = "李四";
        passenger2.setCard(false);
        passenger2.setPackage(false);
        passenger2.setWater(true);
        passenger2.water.name = "矿泉水";
        passenger2.route.startStation = "龙泉";
        passenger2.route.endStation = "天府广场";
        passenger2.setAction("正常");
        passengerList.add(passenger2);

        Passenger passenger3 = new Passenger();
        passenger3.name = "王五";
        passenger3.setCard(true);
        passenger3.card.setBalance(1);
        passenger3.setPackage(false);
        passenger3.setWater(true);
        passenger3.water.name = "有毒";
        passenger3.route.startStation = "龙泉";
        passenger3.route.endStation = "一品天下";
        passenger3.setAction("正常");
        passengerList.add(passenger3);
    }

    private void initStations() {
        stations.put("犀浦", 1);
        stations.put("茶店子", 2);
        stations.put("一品天下", 3);
        stations.put("蜀汉路", 4);
        stations.put("天府广场", 5);
        stations.put("东大路", 6);
        stations.put("成渝立交", 7);
        stations.put("惠王陵", 8);
        stations.put("成都行政学院", 9);
        stations.put("书房", 10);
        stations.put("龙泉", 11);
    }

    public void saleCard(int i) {

        if (passengerList.get(i).isCard()) {
            System.out.println("刷卡消费");
        } else {
            System.out.println(passengerList.get(i).name + "办卡");
        }
    }

    public void run() {

        for (int i = 0; i < passengerList.size(); i++) {

            Passenger passenger = passengerList.get(i);

            System.out.println("乘客基本信息：\n"+"姓名："+passenger.name+"\n起点站："+passenger.route.startStation

                    +"\n终点站："+passenger.route.endStation
            );

            passenger.hasCard();
            passenger.hasPackage();
            passenger.hasWater();

            saleCard(i);

            monitorPerson.warnigPassenger(i);
            passenger.inStatation();

            monitorSystem.callThePolice(i);

            salesman.chargeCard(passenger, 10, i);
            System.out.println("余额：" + (passenger.card.getBalance() - passenger.outStation(i)));
            System.out.println("---------------分割线----------------");
            new SubweyTravel().getIs_normal();
        }
    }
}
